//
//  DNAuthorizedTool.m
//  DNCodeConfuseDemo
//
//  Created by hushuaike on 17/8/22.
//  Copyright © 2017年 hushuaike. All rights reserved.
//

#import "DNAuthorizedTool.h"
#import <UserNotifications/UNUserNotificationCenter.h>
#import <UserNotifications/UNNotificationSettings.h>
#import <UIKit/UIKit.h>
#define DNIOS(x) ([[[UIDevice currentDevice] systemVersion] floatValue] >= (x))

@implementation DNAuthorizedTool
+ (void)DNCheckCTCellularDataWithCallBack:(void(^)(CTCellularDataRestrictedState status))callBack
{
    if(DNIOS(9)){
        CTCellularData *cellData = [[CTCellularData alloc] init];
        [cellData setCellularDataRestrictionDidUpdateNotifier:^(CTCellularDataRestrictedState status)
         {
             dispatch_async(dispatch_get_main_queue(), ^{
                 !callBack ? : callBack(status);
             });
         }];
    }else{
        !callBack ? : callBack(YES);//9以下貌似没有这个权限;
    }
}

+ (void)isUseCTCellularDataWithCallBack:(void (^)(BOOL))callBack
{
    [self DNCheckCTCellularDataWithCallBack:^(CTCellularDataRestrictedState status) {
        if(status == kCTCellularDataRestricted)
        {
            !callBack ? : callBack(YES);
        }
    }];
}

+ (void)DNCheckUserNotificationWithCallBack:(void (^)(BOOL))callBack
{
    if(DNIOS(10))
    {
        [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
            !callBack ? : callBack(settings.authorizationStatus == UNAuthorizationStatusDenied);
        }];
        return;
    }else  if(DNIOS(8))
    {
        
        UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
        !callBack ? : callBack(settings.types == UIUserNotificationTypeNone);
        return;
    }
    !callBack ? : callBack(NO);//ios7 没有权限限制;
}


@end
